<%--
  Created by IntelliJ IDEA.
  User: stella
  Date: 2024/12/13
  Time: 14:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="../assets/css/mainIndex.css" />
</head>
<body>
<div class="top">
    <span class="dog">斯派克狗小说网站</span>
    <span class="times">
        <span class="hour">xx</span>:<span class="minute">xx</span>:<span class="second">xx</span><br />
        <span class="nowDay"></span>
      </span>
</div>

<script>
    var hour = document.querySelector(".hour");
    var minute = document.querySelector(".minute");
    var second = document.querySelector(".second");
    var nowDay = document.querySelector(".nowDay")

    function getTime() {
        let now = new Date();
        let hours = now.getHours();
        let minutes = now.getMinutes();
        let seconds = now.getSeconds();

        const day = now.getDay();
        const days = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
        oneDay = days[day]
        nowDay.innerHTML = oneDay


        // console.log(hours);
        countdown(hours,minutes,seconds)

    }

    function countdown(hours,minutes,seconds) {
        if (hours <= 9) {
            hour.innerHTML = '0' + hours
        } else {
            hour.innerHTML = hours
        }
        if (minutes <= 9) {
            minute.innerHTML = '0' + minutes
        } else {
            minute.innerHTML = minutes
        }
        if (seconds <= 9) {
            second.innerHTML = '0' + seconds
        } else {
            second.innerHTML = seconds
        }
    }

    getTime()
    setInterval(getTime,1000)
</script>
</body>
</html>
